﻿'///////////////////////////////////////////////////////////////////////////
'////MODULE LIGHTING- Holds all light for a "Level", lights are loaded
'////       either manually or automatic by "Mod_Level_Util". Each light
'////       can be enabled/disabled moved and aimed at loadtime or runtime.
'////   SHADOWING- Shadow system can be enabled/disabled through this 
'////           this module, each light can be set to cast a shadow to the
'////           "Mod_Mesh_Dynamic(s)" that have shadowing enabled.
'////   1_2012 mauricedatt@yahoo.com
'////
'///////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////
'///////  THIS Projects website with ongoing updates etc...  /////
'///////  http://sourceforge.net/projects/ ///////////////////////
'/////////////////////////////////////////////////////////////////

 
Imports System.IO
Imports System.Math
Imports System.Drawing
Imports SlimDX
Imports SlimDX.Direct3D9
Imports Microsoft
Imports Microsoft.VisualBasic






'//////////ENUM AND STRUCTURE for the Lighting Module////////////////

Public Structure Light_Spot_Settings

    Public SpotFalloff_Distance As Single
    Public SpotConeInner_Size As Single
    Public SpotConeOutter_Size As Single
    Public SpotTarget As Integer 'Mod_Mesh_Dynamic  'Allows for moving target by updating each render (idx mesh)

End Structure

Public Structure Light_Flicker

    Public Enabled As Boolean
    Public FlickerInterval As Integer 'set at loadtime randomly or manually
    Public FlickerCurrentTime As Integer 'time from last flicker

End Structure

Public Structure Light_Struct

    Public LightType As LightType
    Public LightColor As Color4
    Public LightIntensity As Integer 'Brightness, Scale the R G B values by this number
    Public LightFlicker As Light_Flicker  'Random flicker Option
    Public Spot_Settings As Light_Spot_Settings 'Setup for LightType - Spot
    Public Light_Pos As Vector3 'Global position
    Public Light_Mesh As Integer 'Mod_Mesh_Dynamic 'Set by level_util, used to keep the light updated
    Public Light_ChildMesh_Num As Integer 'Set to the Child/Sibling Mesh for pos/oriention
    Public Light_IS_Child As Boolean 'FALSE if the light hooks to a parent,TRUE child/sibling
    Public Light_Light As Light 'THE LIGHT set by create light using "THIS" DATA
    Public Light_Curr_Enabled As Boolean   'set enabled if true in "LightsUpdate"
End Structure
'/////////////////////////////////////////////////////////////////////////////////////////


Public Class Mod_Lighting

    '////////////////////////
    Public PosTest As Vector3 'test position of a light to be moved with the keyboard
    Public Default_Light_Intensity As Integer

    Public LightCount As Integer
    Public Lights() As Light_Struct 'Declare max lights per scene
    '/Enable or Disable the lighting in the SCENE
    Public Lighting_System_ON As Boolean = True
    Public LightStdColor As Color4 = Color.IndianRed 'default color
    Public LightBkgrStdColor As Color4 = Color.White
    Public LightStdBright As Integer = 50 '1 to 100 being normal ranges (no limit tho)
    Public Light_MaxNum_Currently As Integer
    ''' <summary>
    ''' REQUIRED, CALL FIRST OR CALL AFTER PROPERTIES ARE CHANGED
    ''' TO RE-INIT THE LIGHTING SYSTEM. this sets the Device 
    ''' properly for using lights with certain settings.
    ''' </summary> 
    Public Sub Init_Light_System(ByVal device As Device, ByVal MaxLights_ As Integer, _
                                 Optional ByVal Light_Default_Intensity As Integer = 50)

        'set public variable
        Light_MaxNum_Currently = MaxLights_
        Default_Light_Intensity = Light_Default_Intensity '/set for use when "Create_struct..."

        'redim lights
        ReDim Preserve Lights(MaxLights_)

        'set device switches
        device.SetRenderState(RenderState.Lighting, Lighting_System_ON)
        device.SetRenderState(RenderState.DitherEnable, True)
        device.SetRenderState(RenderState.ZEnable, True)
        'Device.SetRenderState(RenderState.Ambient, True)

        ' Turn on fog '
        Dim FogENABLE As Boolean = True
        Dim fFogStart As Single = 3000.0F
        Dim fFogEnd As Single = 7000.0F
        device.SetRenderState(RenderState.FogEnable, FogENABLE)
        device.SetRenderState(RenderState.FogColor, RGB(255, 255, 255))
        device.SetRenderState(RenderState.FogTableMode, FogMode.None)
        device.SetRenderState(RenderState.FogVertexMode, FogMode.Linear)
        device.SetRenderState(RenderState.RangeFogEnable, False)
        device.SetRenderState(RenderState.FogStart, fFogStart)
        device.SetRenderState(RenderState.FogEnd, fFogEnd)

    End Sub

    ''' <summary>
    ''' Checks that the lights are in the proper position based on
    ''' the Meshes they are attached to, then run the "LightFlicker"
    ''' routine if enabled per light.
    ''' BRIGHTNESS is COLOR multiplied by Intensity at rendertime.u
    ''' </summary>
    Public Sub LightsUpdate(ByVal device As Device)

        Dim A As Integer, IntColor As New Color4

        'check for enabled lights and set them
        For A = 0 To LightCount - 1


            'With Lights(A)

            '/GET the Current position (Global)
            '    If Lights(A).Light_IS_Child = True Then

            '        'get GLOBAL position of child/sibling

            '        With LevelMod.Level_X_File

            '            Dim MpTransfPos As Vector3, DiffScaledPos As Vector3
            '            Dim NewMeshpos As Vector3, ScaleV As Vector3, SCaledPos As Vector3

            '            Dim Localpos As Vector3, MeshPMat As Matrix, MeshPZPMat As Matrix, MeshPpos As Vector3

            '            'get Mesh Part Matrix
            '            MeshPMat = .Transform_Mats(Lights(A).Light_ChildMesh_Num)

            '            'get LENGTH of the matrix(s) rows (scalars) to determin xyz "scale"
            '            ScaleV.X = Abs(MeshPMat.M11 + MeshPMat.M12 + MeshPMat.M13)
            '            ScaleV.Y = Abs(MeshPMat.M21 + MeshPMat.M22 + MeshPMat.M23)
            '            ScaleV.Z = Abs(MeshPMat.M31 + MeshPMat.M32 + MeshPMat.M33)

            '            'get the local position
            '            Localpos.X = MeshPMat.M41
            '            Localpos.Y = MeshPMat.M42
            '            Localpos.Z = MeshPMat.M43

            '            'create zero position matrix from meshpmt
            '            ' MeshPZPMat = MeshPMat
            '            ' MeshPZPMat.M41 = 0
            '            ' MeshPZPMat.M42 = 0
            '            ' MeshPZPMat.M43 = 0

            '            'transform the local position by the local matrix
            '            Dim TransformedLocalPOS As Vector3, TransfLSP As Vector3, TransFZLSP As Vector3
            '            'TransfLSP = Vector3.TransformCoordinate(Localpos, MeshPMat)
            '            TransFZLSP = Vector3.TransformCoordinate(New Vector3(0, 0, 0), MeshPMat)
            '            'TransformedLocalPOS = Vector3.TransformCoordinate(Localpos, MeshPZPMat) 'MeshPZPMat)
            '            'Set the NEW position to be scaled globally
            '            SCaledPos = TransFZLSP

            '            'Convert local to Global THROUGH parent matrix
            '            Dim GlobalRootMat As Matrix, RootScale As Vector3, ScaledL_to_G As Vector3
            '            '''''RootScale = .StartScale
            '            ''''' GlobalRootMat = .RootFrame.TransformationMatrix
            '            '   calc global scale to local position
            '            ScaledL_to_G.X = SCaledPos.X * .StartScale.X
            '            ScaledL_to_G.Y = SCaledPos.Y * .StartScale.Y
            '            ScaledL_to_G.Z = SCaledPos.Z * .StartScale.Z
            '            '   calc global posiiton offset to local position 
            '            Dim ScaledOffsetGlobalPOS As Vector3, GlobalScaledStartPos As Vector3
            '            GlobalScaledStartPos.X = .StartPosition.X * .StartScale.X
            '            GlobalScaledStartPos.Y = .StartPosition.Y * .StartScale.Y
            '            GlobalScaledStartPos.Z = .StartPosition.Z * .StartScale.Z

            '            ScaledOffsetGlobalPOS = Vector3.Add(ScaledL_to_G, GlobalScaledStartPos)
            '            'ScaledOffsetGlobalPOS = Vector3.Add(ScaledL_to_G, .StartPosition)


            '            Lights(A).Light_Light.Position = ScaledOffsetGlobalPOS   '''''NewMeshpos...


            '        End With
            '    Else

            '        Lights(A).Light_Light.Position = Calc_Parent_Global_Pos(Lights(A).Light_Mesh, A)

            '    End If

            '    With Lights(A)
            '        'Dim newpp As SlimDX.Vector3 = .Light_Light.Position
            '        'newpp.X = 789
            '        '.Light_Light.Position = newpp
            '        .Light_Light.Range = 1000
            '        Dim Ncol As Color4
            '        Ncol = .LightColor
            '        'Ncol.Red = 10
            '        'Ncol.Blue = 10
            '        ' Ncol.Green = 10
            '        .Light_Light.Ambient = Ncol
            '        .Light_Light.Diffuse = Ncol
            '        .Light_Light.Specular = Ncol


            '        '/Set the INTENSITY of the light
            '        IntColor = LightIntensity(.LightColor, .LightIntensity * 99) '*****DETERMIN INTENSITY
            '        .Light_Light.Ambient = IntColor
            '        .Light_Light.Diffuse = IntColor

            '        device.SetLight(A, .Light_Light)

            '    End With

            '    '/Enable/Disable the light
            '    device.EnableLight(A, Lights(A).Light_Curr_Enabled)

        Next

        'Set material so meshes are not black
        Dim material As New SlimDX.Direct3D9.Material()
        material.Diffuse = LightBkgrStdColor
        material.Ambient = LightBkgrStdColor
        device.Material = material


    End Sub

    ''' <summary>
    ''' Checks which lights are set to flicker and
    ''' enables/disables them accordingly.
    ''' Called at Rendertime from "LightsUpdate".
    ''' </summary>
    Private Sub LightFlicker_(ByVal Light As Light_Struct)

    End Sub

    ''' <summary>
    ''' Scales the R,G,B values of the lights color to
    ''' make it brighter/dimmer.
    ''' </summary>
    Public Function LightIntensity(ByVal ColorIN_ As Color4, _
                                    ByVal Intensity_ As Integer) As Color4
        Dim OutColor As Color4, Bright_ As Single
        'Scale Intensity_ making the changes to OUTCOLOR smaller
        Bright_ = Intensity_ * 0.03F
        'Scale R G B
        OutColor.Red = ColorIN_.Red * Bright_
        OutColor.Green = ColorIN_.Green * Bright_
        OutColor.Blue = ColorIN_.Blue * Bright_

        'OUTPUT-
        LightIntensity = OutColor

    End Function

    ''' <summary>
    ''' CALLED from "Create_Light_Struct" to create the
    ''' light into our Directx scene. "Create_Light_Struct"
    ''' is called from "Mod_Level_Util" automatically.
    ''' </summary>
    ''' <param name="LightType_"></param>
    ''' <param name="Position_">Global</param>
    ''' <param name="Color_"></param>  
    ''' <param name="Direction_">Only when TYPE = Directional</param>
    ''' <param name="Target">Only when TYPE = Spot</param>
    Private Function CreateLight(ByVal LightType_ As LightType, ByVal Position_ As Vector3, _
                                ByVal Device_ As Device, _
                                Optional ByVal Color_ As Color4 = Nothing, _
                                Optional ByVal Direction_ As Vector3 = Nothing, _
                                Optional ByVal Target As CD3DMesh = Nothing) _
                                As Light

        '///CHECK FOR TOTAL LIGHT COUNT AND RE-INIT LIGHT SYSTEM IF NEEDED
        If LightCount + 1 > Light_MaxNum_Currently Then

            'increase Maximum Lights by 10
            Dim Newmax As Integer
            Newmax = Light_MaxNum_Currently + 10
            Init_Light_System(Device_, Newmax)

        End If

        'Get the Current Color for the new light
        Dim CurrColor As Color4
        If Color_ = Nothing Then
            CurrColor = LightStdColor
        Else
            CurrColor = Color_
        End If

        'Declare the new light
        Dim NewLight As Light
        NewLight = New Light()

        '//Fill "Newlight"s properties depending on TYPE
        With NewLight
            '/Shared variables

            'position
            .Position = Position_
            'if direction is not given default it
            If Direction_ = Nothing Then
                .Direction = New Vector3(0.0F, -1, 0.0F)
            Else
                .Direction = Direction_ 'TARGET OVERIDES THIS
            End If
            'set color
            .Diffuse = CurrColor
            .Ambient = CurrColor

            '/Per Type variables
            Select Case LightType_

                Case LightType.Directional
                    .Type = LightType.Directional

                Case LightType.Point
                    .Type = LightType.Point

                    .Range = 100.0F
                    .Attenuation0 = 0.05F
                    .Attenuation1 = 0.05F
                    .Attenuation2 = 0.03F
                Case LightType.Spot
                    .Type = LightType.Spot
                    .Range = 100
                    'overide Direction if Target is given
                    If Target Is Nothing Then
                        'error
                        MsgBox("Error:Spot light has no TARGET", MsgBoxStyle.Exclamation, _
                            "MOD_LIGHTING.CREATELIGHT")
                    Else
                        'GET the global position of the Mesh Object
                        Dim TargetPos As Vector3, TargetDir As Vector3, CurrPos As Vector3
                        'FIND center of target
                        CurrPos = Position_
                        TargetPos = Target.BoundingSphere.Center
                        'SUBTRACT Target from Position to create a RAY
                        TargetDir = Vector3.Subtract(TargetPos, CurrPos)
                        'NORMALIZE - making the ray have a length of 1 (directional)
                        TargetDir = Vector3.Normalize(TargetDir)
                        'OVERIDE direction with "TargetDir"
                        .Direction = TargetDir
                    End If
            End Select
        End With

        'OUTPUT-
        CreateLight = NewLight

    End Function

     
    '    Public Function Create_Light_Struct(ByVal device As Device, _
    '                                        ByVal Mod_Mesh_ As CD3DMesh, _
    '                                        ByVal LightType_ As LightType, _
    '                                        Optional ByVal Mod_Mesh_Childnum As Integer = -1, _
    '                                        Optional ByVal Intensity_ As Integer = Nothing, _
    '                                        Optional ByVal Color_ As Color4 = Nothing, _
    '                                        Optional ByVal Target As CD3DMesh = Nothing _
    '                                        ) As Light_Struct

    '        Dim Direction_ As Vector3, Cnum As Integer, NewLightS As Light_Struct
    '        Dim Currpos As Vector3, ChildNum As Integer = Mod_Mesh_Childnum
    '        Dim GlobalPosition As Vector3

    '        '//Check if CHILDNUM is GIVEN (if not light object is a PARENT)
    '        If Mod_Mesh_Childnum > -1 Then
    '            'Check if the CHILD/SIBLING and its PARENT are loaded (Msgbox the error if not)
    '            If Mod_Mesh_.Mesh_Count < Mod_Mesh_Childnum Then GoTo ErrorLight

    '            'ChildNum used to get Position/Orientation for the light
    '            NewLightS.Light_ChildMesh_Num = Mod_Mesh_Childnum

    '            'set Child True for updating/render time
    '            NewLightS.Light_IS_Child = True


    '        Else
    '            NewLightS.Light_ChildMesh_Num = -1
    '            NewLightS.Light_IS_Child = False
    '        End If

    '        '//set mod_mesh to newlight
    '        If Mod_Mesh_ IsNot Nothing Then
    '            NewLightS.Light_Mesh = Mod_Mesh_
    '        End If

    '        '//get current position
    '        If NewLightS.Light_IS_Child = True Then

    '            'get GLOBAL position of child/sibling
    '            GlobalPosition = Mod_Mesh_.Meshpart_GetPOS_Global(NewLightS.Light_ChildMesh_Num)
    '            Currpos = GlobalPosition

    '        Else

    '            Currpos = Calc_Parent_Global_Pos(Mod_Mesh_, Mod_Mesh_Childnum)

    '        End If

    '        NewLightS.Light_Pos = Currpos
    '        'current light number 
    '        Cnum = LightCount
    '        'set intensity
    '        If Intensity_ = Nothing Then
    '            NewLightS.LightIntensity = LightStdBright
    '        Else
    '            NewLightS.LightIntensity = Intensity_
    '        End If
    '        'set color
    '        If Color_ = Nothing Then
    '            NewLightS.LightColor = LightStdColor
    '        Else
    '            NewLightS.LightColor = Color_
    '        End If

    '        'set type
    '        NewLightS.LightType = LightType_
    '        'set target mesh
    '        NewLightS.Spot_Settings.SpotTarget = Target
    '        'set light enabled
    '        NewLightS.Light_Curr_Enabled = True
    '        'Calc direction DEPENDING on type
    '        Select Case LightType_
    '            Case LightType.Point
    '                Direction_ = Nothing
    '            Case LightType.Directional
    '                'TEMP aim light using LightMeshes matrix
    '                '   this can be overiden by a "Level script"
    '                '   or manually in code
    '                Direction_.X = Mod_Mesh_.RootFrame.TransformationMatrix.M11
    '                Direction_.Y = Mod_Mesh_.RootFrame.TransformationMatrix.M22
    '                Direction_.Z = Mod_Mesh_.RootFrame.TransformationMatrix.M33
    '            Case LightType.Spot
    '                MsgBox("SPOT LIGHT not yet setup", MsgBoxStyle.Critical, "Create_Light_Struct")

    '        End Select

    '        '/CREATE THE LIGHT
    '        NewLightS.Light_Light = CreateLight(LightType_, Currpos, device, Color_, Direction_, Target)

    '        'OUTPUT-
    '        Lights(Cnum) = NewLightS
    '        device.SetLight(Cnum, Lights(Cnum).Light_Light)
    '        LightCount = LightCount + 1
    '        Create_Light_Struct = NewLightS 'output the new light

    '        Exit Function

    'ErrorLight:
    '        MsgBox("Light Creation using Mesh Child/Sibling for position must be called ter the Parent mesh is loaded", MsgBoxStyle.Critical, "Crete_Light_Struct, Meshpart #" & ChildNum)

    '    End Function

    ''' <summary>
    ''' GETS the Global position of a Parent
    ''' Mesh, using Start pos,scale.
    ''' </summary>
    Private Function Calc_Parent_Global_Pos(ByVal Mod_Mesh_ As CD3DMesh, _
                                            ByVal Curr_M_Num As Integer) As Vector3

        'transform the Center to Global
        Dim SScale As Vector3, Spos As Vector3, Tmat As Matrix
        Dim NewPA As Vector3, NewPB As Vector3, BSCenter As Vector3
        Tmat = Mod_Mesh_.RootFrame.TransformationMatrix
        '//temp///            BSCenter = Mod_Mesh_.BoundingSphere.Center
        If Curr_M_Num < 0 Then
            BSCenter = Mod_Mesh_.BoundingSphere.Center
        Else
            BSCenter.X = Mod_Mesh_.Mesh_BoundingSphere(Curr_M_Num).Center.X
            BSCenter.Y = Mod_Mesh_.Mesh_BoundingSphere(Curr_M_Num).Center.Y
            BSCenter.Z = Mod_Mesh_.Mesh_BoundingSphere(Curr_M_Num).Center.Z
        End If

        Tmat.M41 = 0
        Tmat.M42 = 0
        Tmat.M43 = 0
        SScale = Mod_Mesh_.StartScale
        Spos = Mod_Mesh_.StartPosition
        'Transform CENTER
        NewPA = Vector3.TransformCoordinate(BSCenter, Tmat)
        'Scale
        NewPB.X = (NewPA.X * SScale.X) + Spos.X
        NewPB.Y = (NewPA.Y * SScale.Y) + Spos.Y
        NewPB.Z = (NewPA.Z * SScale.Z) + Spos.Z
        'OUTPUT
        Return NewPB

    End Function


    ''' <summary>
    ''' Calculates the lighting for SKINNED MESHES,
    ''' (SINGLE light per call to function), used to 
    ''' set the "Mesh_Effect"s "light direction". Directional
    ''' lights are averaged together (direction/color), Point
    ''' lights are scaled down depending on range then averaged.
    ''' SCALEDINTENSITY_OUT is output from the intensity scaled
    ''' down by distance from POINT lights.
    ''' </summary>
    Private Function Light_Calc_SkinnedMesh(ByVal LightNum_ToCheck As Integer, _
                                           ByVal SkinnedMesh_Pos As Vector3, _
                                           ByRef ScaledIntensity_Out As Single, _
                                           ByRef LightInRange As Boolean) As Vector4

        'check a single light against the SKINNED mesh's Position
        Dim CurrRay As Vector3, LightPos As Vector3, TempDir As Vector4


        '/check if the LIGHT is within range of the MESH
        '   if lights range is <1 then range is INFINITE OR if type = Directional
        If Lights(LightNum_ToCheck).Light_Light.Range < 1 Then LightInRange = True


        Select Case Lights(LightNum_ToCheck).LightType
            Case LightType.Directional
                '//DIRECTIONAL light only from there direction, no position

                'set IN RANGE = true
                LightInRange = True

                'get lights direction
                CurrRay = Lights(LightNum_ToCheck).Light_Light.Direction
                'copy values
                TempDir.X = CurrRay.X
                TempDir.Y = CurrRay.Y
                TempDir.Z = CurrRay.Z
                TempDir.W = 0
                '/normalize
                TempDir = Vector4.Normalize(TempDir)

                '///output INTENSITY -(offset the reduction in Mod_Mesh_Dynamic.DrawMesh...)
                ScaledIntensity_Out = 5 * Lights(LightNum_ToCheck).LightIntensity

            Case LightType.Point
                '//POINT lights have Position but ALL direction lighting

                'get pos
                LightPos = Lights(LightNum_ToCheck).Light_Light.Position
                'subtract positions to get light direction/ray
                CurrRay = Vector3.Subtract(SkinnedMesh_Pos, LightPos)
                'copy values
                TempDir.X = CurrRay.X
                TempDir.Y = CurrRay.Y
                TempDir.Z = CurrRay.Z
                TempDir.W = 0
                '/normalize
                TempDir = Vector4.Normalize(TempDir)

                '/calculate INTENSITY
                Dim CurrInt As Single, TempDist As Single, CurrRange As Single
                Dim NewRange As Single, NewDivScale As Single

                'get intensity
                CurrInt = Lights(LightNum_ToCheck).LightIntensity
                'calc distance
                TempDist = Vector3.Distance(LightPos, SkinnedMesh_Pos)
                '///OUTPUT scaled intensity
                'find range
                CurrRange = Lights(LightNum_ToCheck).Light_Light.Range
                NewRange = (CurrRange - TempDist)
                If NewRange < 0 Then
                    'TOO FAR away to light
                    NewRange = 0
                    ScaledIntensity_Out = 0
                    LightInRange = False
                Else
                    'set IN RANGE = TRUE 
                    LightInRange = True
                    'calc intensity by % of distance/range
                    NewDivScale = 1 - (TempDist / CurrRange)
                    'OUTPUT-
                    ScaledIntensity_Out = CurrInt * NewDivScale
                End If


        End Select

        'OUTPUT-
        Return TempDir

    End Function

    Public Sub Light_Check_InRange(ByVal SkinnedMEshPos As Vector3, _
                                        ByRef Total_InRange As Integer, _
                                        ByRef Lights_Dir_Array() As Vector4, _
                                        ByRef Lights_Color_Array() As Color4, _
                                        ByRef Lights_Intensity_Array() As Integer, _
                                        ByRef LightNumbs() As Integer)

        Dim CurrSInt As Single, InRange As Boolean, A As Integer
        '/set NEW arrays
        ReDim Lights_Dir_Array(0)
        ReDim Lights_Color_Array(0)
        ReDim LightNumbs(0)
        ReDim Lights_Intensity_Array(0)

        '/loop through all lights testing for Range/Distance
        For A = 0 To LightCount - 1

            Dim Direction As Vector4
            'find if the current light is in range
            'USE "CurrSint" as NEW INTENSITY for each light
            Direction = Light_Calc_SkinnedMesh(A, SkinnedMEshPos, CurrSInt, InRange)

            If InRange = True Then


                ReDim Preserve Lights_Dir_Array(Total_InRange)
                ReDim Preserve Lights_Color_Array(Total_InRange)
                ReDim Preserve LightNumbs(Total_InRange)
                ReDim Preserve Lights_Intensity_Array(Total_InRange)

                LightNumbs(Total_InRange) = A
                Lights_Color_Array(Total_InRange) = Lights(A).LightColor
                Lights_Dir_Array(Total_InRange) = Direction
                Lights_Intensity_Array(Total_InRange) = CurrSInt


                Total_InRange = Total_InRange + 1


            End If

        Next


    End Sub


End Class


